import { DocumentEventCenter } from "../base_frame/DocumentEventCenter";
import { IShaderBase } from "../base_frame/IShaderBase";
import { TextureCube } from "./TextureCube";

export class TextureCubeCommon extends TextureCube implements IShaderBase {
    isCommonBuffer: boolean = true;
    id:number = 0;
    draw(gl: WebGL2RenderingContext | WebGLRenderingContext): void {
        if (this.count && this.cubeTexture) {
            gl.clearColor(1.0, 0.2, 0.4, 1.0);
            gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
            // gl.viewport(0,0,256,256);
            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,this.indiceBuffer);
            this.resetBuffer(gl, this.posBuffer, this.a_Position, 3, gl.FLOAT);
            this.resetBuffer(gl, this.coordBuffer, this.a_TexCoord, 2, gl.FLOAT);

            gl.activeTexture(gl.TEXTURE0);
            gl.bindTexture(gl.TEXTURE_2D, this.cubeTexture);
            gl.drawElements(gl.TRIANGLES, this.count, gl.UNSIGNED_BYTE, 0);
            // 让他循环转起来
            this.moduleMatrix.rotate(1, 0, 1, 0);
            DocumentEventCenter.sendEvent(DocumentEventCenter.updateRenderFlag);
        }
    }
}